package com.itbaizhan.openhis.controller.system;

import com.itbaizhan.openhis.dto.RegisteredItemDto;
import com.itbaizhan.openhis.service.RegisteredItemService;
import com.itbaizhan.openhis.utils.ShiroSecurityUtils;
import com.itbaizhan.openhis.vo.AjaxResult;
import com.itbaizhan.openhis.vo.DataGridView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;

@RestController
@RequestMapping("system/registeredItem")
public class RegisteredItemController {


    @Autowired
    private RegisteredItemService registeredItemService;


    /**
     * 分页查询挂号项目
     *
     * @param registeredItemDto
     * @return
     */
    @GetMapping("listRegisteredItemForPage")
    public AjaxResult listRegisteredItemForPage(RegisteredItemDto registeredItemDto) {
        DataGridView dataGridView = registeredItemService.listRegisteredItemForPage(registeredItemDto);
        return AjaxResult.success("查询成功", dataGridView.getData(), dataGridView.getTotal());
    }

    /**
     * 添加挂号项目
     *
     * @param registeredItemDto
     * @return
     */
    @PostMapping("addRegisteredItem")
    public AjaxResult addRegisteredItem(@Validated RegisteredItemDto registeredItemDto) {
        registeredItemDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(registeredItemService.addRegisteredItem(registeredItemDto));
    }

    /**
     * 添加挂号项目
     *
     * @param registeredItemDto
     * @return
     */
    @PutMapping("updateRegisteredItem")
    public AjaxResult updateRegisteredItem(@Validated RegisteredItemDto registeredItemDto) {
        registeredItemDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(registeredItemService.updateRegisteredItem(registeredItemDto));
    }

    /**
     * 根据id查询一个挂号项目
     *
     * @param registeredItemId
     * @return
     */
    @GetMapping("getRegisteredItemById/{registeredItemId}")
    public AjaxResult getRegisteredItemById(@PathVariable @Validated
                                            @NotEmpty(message = "挂号项目ID不能为空") Long registeredItemId) {
        return AjaxResult.success(registeredItemService.getRegisteredItemById(registeredItemId));
    }

    /**
     * 删除挂号项目
     * @param registeredItemIds
     * @return
     */

    @DeleteMapping("deleteRegisteredItemByIds/{registeredItemIds}")
    public AjaxResult deleteRegisteredItemByIds(@PathVariable @Validated
                                                @NotEmpty(message = "需要删除的挂号项目ID不能为空") Long[] registeredItemIds) {
        return AjaxResult.toAjax(registeredItemService.deleteRegisteredItemByIds(registeredItemIds));
    }
}
